<?php
namespace TennisTournament\Persistent;

use Doctrine\ORM\EntityManager;
use TennisTournament\Model\Player;

class PlayerDaoDoctrine extends GenericDaoDoctrine implements PlayerDao {
    const PLAYER_ENTITY = "TennisTournament\Model\Player";

    public function __construct(EntityManager $entityManager) {
        parent::__construct($entityManager, self::PLAYER_ENTITY);
    }

    /**
     * Get best scorer
     * @return Player
     */
    public function getBestScorer() {
        $queryBuilder = $this->entityManager->createQueryBuilder();

        $queryBuilder->select('player')
            ->from(self::PLAYER_ENTITY, "player")
            ->orderBy('player.madePoints - player.obtainedPoints', 'DESC')
            ->setMaxResults(1);

        return $queryBuilder->getQuery()->getResult()[0];
    }


}